<?php
// +----------------------------------------------------------------------
// | Yzncms [ 御宅男工作室 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2018 http://yzncms.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 御宅男 <530765310@qq.com>
// +----------------------------------------------------------------------

// +----------------------------------------------------------------------
// | 后台用户管理
// +----------------------------------------------------------------------
namespace app\api\model;

use app\admin\model\CarModel;
use app\admin\model\College;
use app\api\model\Token;
use app\common\model\AliPay;
use app\common\model\RebateLog;
use EasyWeChat\Factory;
use think\facade\Db;
use think\Model;


class AccessTokenModel extends Model
{
    protected $autoWriteTimestamp = true;
    protected $updateTime = false;

    protected $table = 'yzn_access_token';


    public function accessTokenLog($dy_id,$access_token,$expires_in,$refresh_token,$refresh_expires_in){

        $accessTokenLog = self::get(['dy_id' => $dy_id]);
        if(!$accessTokenLog){
            $accessTokenLog = new self();
            $accessTokenLog->dy_id = $dy_id;
        }
        $accessTokenLog->access_token = $access_token;
        $accessTokenLog->expires_in = time() + $expires_in-3600;
        $accessTokenLog->refresh_token = $refresh_token;
        $accessTokenLog->refresh_expires_in = time() + $refresh_expires_in - 3600;
        if(!$accessTokenLog->save()){
            return false;
        }

        return true;

    }


}
